package com.iplatform.module.privilege;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.io.Serializable;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;

/**
* <p>Title: PriManagerBean</p>
* <p>Description: </p>
* @author RayLLi
* @date 2018年8月27日
 */
@ApiModel()
@Data
public class PriManagerBean implements Serializable, UserDetails {

	/** serialVersionUID*/
	private static final long serialVersionUID = -2631355558319988581L;

	@ApiModelProperty(hidden = true , value = "用户ID", dataType="String")
	private String userId;

	@ApiModelProperty(value = "用户账号", dataType="String")
	private String userCode;

	@ApiModelProperty(hidden = true , value = "用户名称", dataType="String")
	private String userName;
	@ApiModelProperty(hidden = true , value = "用户名称", dataType="String")
	private String realName;

	@ApiModelProperty(value = "用户类型", hidden=true, dataType="String")
	private String mgrType;

	@ApiModelProperty(value = "部门ID", dataType="String")
	private String orgId;

	@ApiModelProperty(value = "单位名称", hidden=true, dataType="String")
	private String orgName;

	@ApiModelProperty(value = "公司ID", dataType="String")
	private String topParentId;

	@ApiModelProperty(value = "最上级名称", hidden=true, dataType="String")
	private String topParentName;

	@ApiModelProperty(value = "密码", hidden=true, dataType="String")
	private String password;

	@ApiModelProperty(value = "是否停用", hidden=true, dataType="String")
	private String stop;

	@ApiModelProperty(value = "是否可用")
	private Boolean isEnable;

	@ApiModelProperty(value = "授权类型，角色用户或者权限用户", hidden=true, dataType="String")
	private String grantType;

	@ApiModelProperty(value = "是否为超级管理员", hidden=true, dataType="String")
	private String isSuper;

	@ApiModelProperty(value = "信息备注", dataType="String")
	private String remark;

	@ApiModelProperty(value = "更新时间", hidden=true, dataType="String")
	private String updatedDt;

	@ApiModelProperty(value = "更新人", hidden=true, dataType="String")
	private String updatedBy;

	@ApiModelProperty(value = "创建时间", hidden=true, dataType="String")
	private String createdDt;

	@ApiModelProperty(value = "创建人", hidden=true, dataType="String")
	private String createdBy;

	@ApiModelProperty(value = "性别", hidden=true, dataType="String")
	private String sex;

	@ApiModelProperty(value = "手机号", dataType="String")
	private String mobile;

	@ApiModelProperty(value = "邮箱", dataType="String")
	private String email;

	@ApiModelProperty(value = "角色信息", hidden=true, dataType="com.iplatform.iplatformuser.privilege.bean.PriRoleBean", required=false)
	private PriRoleBean priRoleBean;

	@ApiModelProperty(value = "角色信息",hidden = true,dataType = "com.iplatform.iplatformuser.privilege.bean.PriRoleBean")
	private List<PriRoleBean> roleBeans;

	@ApiModelProperty(value = "主页地址", hidden=true, dataType="String", required=false)
	private String homeUrl;

	@ApiModelProperty(value = "新主页地址", hidden=true, dataType="String", required=false)
	private String floatHomeUrl;

	@ApiModelProperty(value = "菜单列表", hidden=true, dataType="java.util.List", required=false)
	private List<PriMenuBean> priMenuOpts;

//	@ApiModelProperty(value = "权限信息", hidden=true, dataType="com.iplatform.iplatformuser.function.group.bean.PriGroupInfoBean", required=false)
//	private List<PriGroupInfoBean> priGroupBean;

	@Override
	public Collection<? extends GrantedAuthority> getAuthorities() {
		Collection<GrantedAuthority> collection = new HashSet<>();
		if (priRoleBean != null) {
			collection.add(new SimpleGrantedAuthority(priRoleBean.getRoleName()));
		}

		return collection;
	}

	@Override
	public String getUsername() {
		return userName;
	}

	@Override
	public boolean isAccountNonExpired() {
		return true;
	}

	@Override
	public boolean isAccountNonLocked() {
		return true;
	}

	@Override
	public boolean isCredentialsNonExpired() {
		return true;
	}

	@Override
	public boolean isEnabled() {
		return true;
	}
}